#!/bin/bash
echo -e "Debug:\t File[${BASH_SOURCE[0]}]"
source $(dirname "${BASH_SOURCE[0]}")/deb_lib.sh
current_build_dir=$1
echo "current_build_dir:$current_build_dir"
arch=$(basename "$current_build_dir")
echo "arch  :$arch"
name_prefix=ts_
if [ "$arch" == "arm" ]; then
  architecture=arm
elif [ "$arch" == "armv7" ]; then
  architecture=arm
elif [ "$arch" == "armv6" ]; then
  architecture=armhf
  install_bin_path=/usr/local/bin
  install_config_path=/etc
  install_lib_path=/usr/lib/8300
elif [ "$arch" == "aarch64" ]; then
  architecture=arm64
  install_bin_path=/opt/ts/usr/local/bin
  install_config_path=/opt/ts/etc
  install_lib_path=/opt/ts/usr/lib/8300
  name_prefix=ts_
  path_prefix=/opt/ts
elif [ "$arch" == "x86_64" ]; then
  architecture=amd64
else
  echo "invalid arch:$arch"
  exit
fi
echo "architecture  :$arch"
sub_project_name=$(basename $(dirname $(dirname "$current_build_dir")))
project_source_root=$(dirname $(dirname "$current_build_dir"))
deb_path=$project_source_root/../deb/$arch
deb_package_path=$project_source_root/../deb/$arch/package
build_bin_path=$current_build_dir
echo "current_build_dir:$current_build_dir"
echo "project_source_root:$project_source_root"
echo "sub_project_name:$sub_project_name"
echo "deb_path:$deb_path"
echo "deb_package_path:$deb_package_path"
echo "build_bin_path:$build_bin_path"
#exit
mkdir_directory $deb_package_path
shift #remove the first param
params=$(echo "$@" | sed 's/ /;/g')
if [ "$sub_project_name" == "imch" ]; then
  cp $project_source_root/$name/$name.db $deb_path/$name$install_config_path/$name/
  deb -p $deb_path -N $name_prefix -b $install_bin_path -c $install_config_path -o $params
  deb_ts -p $deb_path -N $name_prefix -b $install_bin_path -c $install_config_path -o $params
else
  deb -p $deb_path -N $name_prefix -b $install_bin_path -c $install_config_path -o $params
fi
exit
